const validatePhone = (rule, value, callback) => {
  if (!/^1[3456789]\d{9}$/.test(value) && value) {
    callback(new Error("请输入正确的手机号"));
  } else {
    callback();
  }
};

var checkEmail = (rule, value, callback) => {
  const mailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/
  setTimeout(() => {
    if (mailReg.test(value) || !value) {
      callback()
    } else {
      callback(new Error('请输入正确的邮箱格式'))
    }
  }, 100)
}

export const listOption = {
  border: true,
  stripe: true,
  menuAlign: "center",
  searchLabelWidth: 100,
  editBtn: false,
  dialogFullscreen: true,
  selection: true,
  labelWidth: "200",
  delBtn: false,
  searchMenuSpan: 6,
  searchSpan: 7,
  align: "center",
  addBtn: false,
  group: [{
    label: '基本信息',
    arrow: false,
    column: [{
        label: "姓名",
        prop: "name",
        span: 12,
        search: true,
        rules: [{
          required: true,
          message: "请输入"
        }]
      },
      {
        label: "身份",
        prop: "identity",
        type: "radio",
        dicFlag: true,
        dicUrl: process.env.VUE_APP_BASE_API + "/admin/dict/find?type=identity_type",
        dicFormatter: res => {
          return (res.data || []).map(o => ({
            label: o.label,
            value: o.value
          }));
        },
        props: {
          label: "label",
          value: "value"
        },
        span: 12,
      },
      {
        label: "职级",
        prop: "position",
        type: "select",
        search: true,
        dicFlag: true,
        dicUrl: process.env.VUE_APP_BASE_API + "/admin/dict/find?type=position_type",
        dicFormatter: res => {
          return (res.data || []).map(o => ({
            label: o.label,
            value: o.value
          }));
        },
        props: {
          label: "label",
          value: "value"
        },
        span: 12,
      },
      {
        label: "所在地",
        prop: "city",
        span: 12,
        type: "cascader",
        props: {
          label: 'region_name',
          value: 'region_id'
        },
        lazy: true,
        lazyLoad(node, resolve) {
          let stop_level = 1;
          let level = node.level;
          let data = node.data || {}
          let code = data.region_id;
          let list = [];
          let callback = () => {
            resolve((list || []).map(ele => {
              return Object.assign(ele, {
                leaf: level >= stop_level
              })
            }));
          }
          if (level == 0) {
            axios.get(`${process.env.VUE_APP_BASE_API}/admin/area/getProvince`).then(res => {
              list = res.data.data;
              callback()
            })
          }
          if (level == 1) {
            axios.get(`${process.env.VUE_APP_BASE_API}/admin/area/getCity?code=${code}`).then(res => {
              list = res.data.data;
              callback()
            })
          } else if (level == 2) {
            axios.get(`${process.env.VUE_APP_BASE_API}/admin/area/getArea?code=${code}`).then(res => {
              list = res.data.data;
              callback()
            })
          }
        }
      },
      {
        label: "职位",
        prop: "position_name",
        span: 12,
      },
      {
        label: "身份标签",
        prop: "identityTag",
        type: "select",
        search: true,
        multiple: true,
        dicFlag: true,
        dicUrl: process.env.VUE_APP_BASE_API + "/admin/identity/all",
        dicFormatter: res => {
          return (res.data || []).map(o => ({
            label: o.name,
            value: o.name
          }));
        },
        props: {
          label: "label",
          value: "value"
        },
        span: 12,
      },
      {
        label: "其他标签",
        prop: "tag",
        type: "select",
        search: true,
        multiple: true,
        dicFlag: true,
        dicUrl: process.env.VUE_APP_BASE_API + "/admin/tags/all",
        dicFormatter: res => {
          return (res.data || []).map(o => ({
            label: o.name,
            value: o.id.toString()
          }));
        },
        props: {
          label: "label",
          value: "value"
        },
        span: 12,
      },
      {
        label: "VIP状态",
        prop: "is_vip",
        span: 12,
        type: 'radio',
        dicData: [{
            label: "VIP",
            value: 1
          },{
            label: "SVIP",
            value: 2
          },
          {
            label: "非会员",
            value: 0
          }
        ],
      },
      {
        label: "是否展示",
        prop: "show",
        span: 12,
        type: 'radio',
        dicData: [{
            label: "展示",
            value: 1
          },
          {
            label: "不展示",
            value: 0
          }
        ],
      },
      {
        label: "到期",
        prop: "dated_time",
        span: 12,
        type: "date"
      },
      {
        label: "毕业院校",
        prop: "education",
        span: 12,
      },
      {
        label: "排序",
        prop: "sort",
        span: 12,
      },
      {
        label: "首页推荐",
        prop: "recommend",
        span: 12,
        type: 'radio',
        dicData: [{
            label: "推荐",
            value: 1
          },
          {
            label: "不推荐",
            value: 0
          }
        ],
      },
      {
        label: "头像",
        prop: "avatar",
        type: 'upload',
        action: process.env.VUE_APP_BASE_API + '/admin/upload/avatar',
        loadText: '附件上传中，请稍等',
        listType: 'picture-img',
        tip: "推荐200*200，1M之内",
        propsHttp: {
          res: 'data',
        },
        span: 24
      },
      {
        label: "个人简介",
        prop: "info",
        type: 'textarea',
        span: 24,
      },
      {
        label: "合作需求",
        prop: "message",
        type: 'textarea',
        span: 24,
      },
    ]
  }, {
    label: '联系方式',
    arrow: false,
    column: [

      {
        label: '手机',
        prop: 'phone',
        span: 12,
        rules: [{
          validator: validatePhone,
          required: false,
          message: '请输入正确手机号',
          trigger: "change"
        }]
      },
      {
        label: '邮箱',
        prop: 'mail',
        span: 12,
        rules: [{
          validator: checkEmail,
          required: false,
          message: '请输入正确邮箱',
          trigger: "change"
        }]
      },
      {
        label: '微信',
        prop: 'wechat',
        span: 12,
      },
    ]
  }, {
    label: '公司介绍',
    arrow: false,
    column: [

      {
        label: '公司',
        prop: 'company_name',
        search: true,
        span: 12,
      },
      {
        label: '行业',
        prop: 'industry',
        span: 12,
        search: true,
        type: "select",
        dicFlag: true,
        dicUrl: process.env.VUE_APP_BASE_API + "/admin/dict/find?type=industry_type",
        dicFormatter: res => {
          return (res.data || []).map(o => ({
            label: o.label,
            value: o.value
          }));
        },
        props: {
          label: "label",
          value: "value"
        },
      },
      {
        label: '轮次',
        prop: 'round',
        type: "select",
        dicFlag: true,
        dicUrl: process.env.VUE_APP_BASE_API + "/admin/dict/find?type=round_type",
        dicFormatter: res => {
          return (res.data || []).map(o => ({
            label: o.label,
            value: o.value
          }));
        },
        props: {
          label: "label",
          value: "value"
        },
        span: 12,
      },
      {
        label: "公司简介",
        prop: "company_info",
        type: 'textarea',
        span: 24,
      },
    ]
  }],
  column: [{
      label: "人物ID",
      prop: "id",
      addDisplay: false,
      viewDisplay: false,
      editDisplay: false,
      span: 24
    }, {
      label: "姓名",
      prop: "name",
      span: 24,
      addDisplay: false,
      viewDisplay: false,
      editDisplay: false
    },
    {
      label: "身份",
      prop: "identity",
      span: 24,
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
    },

    {
      label: "公司",
      prop: "company_name",
      span: 24,
      addDisplay: false,
      viewDisplay: false,
      editDisplay: false,
    },
    {
      label: "职位",
      prop: "position_name",
      span: 24,
      dicFlag: true,
      dicUrl: process.env.VUE_APP_BASE_API + "/admin/dict/find?type=position_type",
      dicFormatter: res => {
        return (res.data || []).map(o => ({
          label: o.label,
          value: o.value
        }));
      },
      props: {
        label: "label",
        value: "value"
      },
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
    },
    {
      label: "行业",
      prop: "industry",
      span: 24,
      dicFlag: true,
      dicUrl: process.env.VUE_APP_BASE_API + "/admin/dict/find?type=industry_type",
      dicFormatter: res => {
        return (res.data || []).map(o => ({
          label: o.label,
          value: o.value
        }));
      },
      addDisplay: false,
      viewDisplay: false,
      editDisplay: false,
    },
    {
      label: "有无联系方式",
      prop: "has_contact",
      type: "radio",
      width: 100,
      search: true,
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
      dicData: [{
          label: "无",
          value: 0
        },
        {
          label: "有",
          value: 1
        }
      ],
      span: 24
    },
    // {
    //   label: "标签",
    //   prop: "tag",
    //   width: 100,
    //   span: 24,
    //   addDisplay: false,
    //   editDisplay: false,
    //   viewDisplay: false,
    //   slot: true,
    //   multiple: true,
    //   type: "select",
    //   dicFlag: true,
    //   dicUrl: process.env.VUE_APP_BASE_API + "/tags/all",
    //   dicFormatter: res => {
    //     return (res.data || []).map(o => ({
    //       label: o.name,
    //       value: o.id.toString()
    //     }));
    //   },
    //   props: {
    //     label: "label",
    //     value: "value"
    //   },
    // },
    {
      label: "身份标签",
      prop: "identityTag",
      width: 100,
      span: 24,
      hide: true,
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
      type: "select",
      dicFlag: true,
      dicUrl: process.env.VUE_APP_BASE_API + "/admin/identity/all",
      dicFormatter: res => {
        return (res.data || []).map(o => ({
          label: o.name,
          value: o.name
        }));
      },
      props: {
        label: "label",
        value: "value"
      },
    },
    {
      label: '是否展示',
      prop: 'show',
      span: 24,
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
      slot: true,
    },
    {
      label: 'VIP',
      prop: "is_vip",
      type: 'radio',
      dicData: [{
          label: "VIP",
          value: 1
        },{
          label: "SVIP",
          value: 2
        },
        {
          label: "不是",
          value: 0
        }
      ],
      span: 24,
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
    },

    {
      label: "认证状态",
      prop: "is_auth",
      span: 24,
      type: 'radio',
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
      dicData: [{
          label: "普通认证",
          value: 1
        },{
          label: "高级认证",
          value: 2
        },
        {
          label: "否",
          value: 0
        }
      ],
    },
    {
      label: '到期',
      prop: 'dated_time',
      span: 24,
      width: 100,
      slot: true,
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
    }
  ]
};
